package edu.dayu.controller;

import com.github.pagehelper.PageInfo;
import edu.dayu.pojo.Applicant;
import edu.dayu.service.ApplicantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/admin")
public class ApplicantController {
    @Autowired
    private ApplicantService applicantService;



    @PostMapping("/applicantList")
    public PageInfo<Applicant> applicantList(Applicant applicant){
        return applicantService.applicantList(applicant);
    }

    @PostMapping("/applicantInsert")
    public boolean applicantInsert (Applicant applicant){
        return applicantService.applicantInsert(applicant);
    }

    @PostMapping("/applicantDelete")
    public void applicantDelete(Applicant applicant) throws InterruptedException {
        applicantService.applicantDelete(applicant);
        String text = "抱歉，"+applicant.getName()+"。我们社团已经招满了。";
        applicantService.sendMail(applicant.getEmail(),text);
    }

    @PostMapping("/applicantPass")
    public void applicantPass(Applicant applicant) throws InterruptedException {
        applicantService.applicantPass(applicant);
        String text = "你好，"+applicant.getName()+"。恭喜你加入本社团！";
        applicantService.sendMail(applicant.getEmail(),text);
    }
}
